﻿using System;
using System.Collections.Generic;
using System.Text;
using FeedDotNet.Common;

namespace ConsoleApplication
{
    class OriginalFeed : IFeedProvider
    {
        private Uri url { get; set; }
        public OriginalFeed(string url)
        {
            this.url = new Uri(url);
        }

        #region IFeedProvider Members

        public Uri FeedUri
        {
            get { return url; }
        }

        public string Key
        {
            get { return url.AbsolutePath; }
        }

        public FeedDotNet.Common.Feed FullFeed
        {
            get;
            set;
        }

        public void PreProcess(ref FeedDotNet.Common.Feed newFeed)
        {   
        }

        public void PostProcess()
        {
            for (int i = this.FullFeed.Items.Count-1; i >= 0; i--)
            {
                FeedItem fi = this.FullFeed.Items[i];
                if (!fi.Published.HasValue ||
                    fi.Published.Value.Subtract(DateTime.Now).Days > 20)
                {
                    this.FullFeed.Items.RemoveAt(i);
                }
            }
        }

        #endregion
    }
}
